<? include 'server_config.php'; 

if($_SESSION['user_idx'] == "k")//임시"")
{
	?>
	<script>
		location.href='login.php';
	</script>
	<?
	return;
}


$board_name=$_GET['name'];
$category_idx=$_GET['category_idx'];
$page=$_GET['page'];

if($board_name=='')
	return;

if($category_idx=='')
	$category_idx=0;

if($page=='')
	$page=1;

$sql="
	SELECT board_idx, title, content FROM ndd_board WHERE name = '$board_name';
";

$result = mysql_query($sql,$connect);

$row = mysql_fetch_row($result);

$board_idx = $row[0];
$board_title = $row[1];
$board_content = $row[2];

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
	<title> New Document </title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="Stylesheet" type="text/css" href="./css/nddCommon.css" />
	<script type="text/javascript" src="./js/jquery-1.6.2.min.js"></script>
	 </head>

 <body>
 <div id="menu_expand"><span></span></div>
	<div id='wrapper'>
		<?
        include "top_menu.php";
        ?>
				
		<div id='left_bg'>
		</div>


		<div id='title'>
			<div id='title_margin_top'><span></span></div>
			<div style='width:195px;height:29px;float:left;'></div>
			<div style='width:41px;height:29px;float:left;'><img src="./img/top_icon_input.png"></div><div style='height:29px;float:left;margin-top:3px;'><span id='article_content' >귀하의 상담, 이야기를 입력해 주세요.&nbsp;</span></div><div style='height:29px;float:left;'><img src="./img/button_view_my_chart.png"></div>
		</div>
		
		<?
		$current_file = basename(__FILE__);
		include 'side_menu_input.php';
		?>

		<div id='middle_bg'>
		</div>

		<div id='document_content' style="width:776px;float:left;">
			<div style='height:2px;width:100%;background:#cccccc;float:left;'><span><span></div>
			<div style='height:3px;width:100%;float:left;'><span><span></div>

			<div style='width:100%;background:#F2F2F2;float:left;border:1px solid #E9E9E9;padding-top:25px;'>
				<div style='width:30px;height:450px;float:left;'></div>
				<div style='width:740px;height:27px;float:left;'>
				
				1. 어떤 상담, 이야기를 하시겠습니까?
	
				</div>
				<div style='width:30px;height:312px;float:left;'></div>
				
				
				
				<form action='board_write.php' method='post' enctype="multipart/form-data" name='fwrite'>
					<input type='hidden' name='board_name' value='<? echo $board_name; ?>'>
					<input type='hidden' name='board_idx' value='<? echo $board_idx; ?>'>
					<input type='hidden' name='page' value='<? echo $page; ?>'>
	
					<?
	
						if ($document_idx !="")
						{
							$sql="
								SELECT title, content, category_idx FROM ndd_document WHERE document_idx = $document_idx;
							";
	
							$result = mysql_query($sql,$connect);
	
							$row = mysql_fetch_row($result);
	
							$document_title = $row[0];
							$document_content = $row[1];
							$document_category_idx = $row[2];
						}
						else
						{
							$document_title = "";
							$document_content = "";
							$document_category_idx = "";
						}
						
					?>
	
					<input type='hidden' name='document_idx' value='<? echo $document_idx; ?>'>
					<input type='hidden' name='document_category_idx' value='<? echo $document_category_idx; ?>'>
	
	
		
		
					<div style='width:710px;height:30px;float:left;'>
					
					<input type='hidden' name='category_idx' id='category_idx' value="">
					

					<script>
					
					function set_category(_category_idx)
					{
						if($('#category_idx').val()!="")
						{
							$("#category_"+$('#category_idx').val()).css({"background-color":"white"});
					
						}

						
						$('#category_idx').val(_category_idx);
						$("#category_"+_category_idx).css({"background-color":"#e6e6e6"});
					
					}
						
					</script>
	
					<!--select name='category_idx'-->
					<? 
						$sql="
							SELECT category_idx, name FROM ndd_category A WHERE board_idx = '$board_idx' AND upper_category_idx=0 ORDER BY A.order;
						";
	
						$result = mysql_query($sql,$connect);
						
						$min_category_value="";
	
						while($row = mysql_fetch_row($result))
						{
							if($min_category_value=="")
								$min_category_value=$row[0];
								
							if ($category_idx==$row[0] || $document_category_idx==$row[0])
							{
							
					?>
							<div style='width:70px;height:30px;background:#e6e6e6;float:left;border:1px solid #e6e6e6;padding-top:5px;text-align:center;cursor:pointer;' id="category_<? echo $row[0];?>" onclick='set_category(<? echo $row[0];?>);'>
								<? echo $row[1];?>
								<script>
								set_category(<? echo $row[0];?>);
								</script>
							</div>
						
					<?
							}
							else
							{
							?>
							<div style='width:70px;height:30px;background:#ffffff;float:left;border:1px solid #e6e6e6;padding-top:5px;text-align:center;cursor:pointer;' id="category_<? echo $row[0];?>" onclick='set_category(<? echo $row[0];?>);'>
								<? echo $row[1];?>
							</div>
							
							<?
							}
						
						}
						
						?>

					<script>
					if($('#category_idx').val()=="")
					{
						set_category(<? echo $min_category_value;?>);
					}
					</script>


						<?
						

					?>
					</div>
					<div style='width:595px;height:502px;background:#e6e6e6;float:left;padding-top:5px;padding-left:45px;'>
						<br>
					
						<input type='text' name='title' style='width:433px;' value="<? echo $document_title;?>">
						<br>
						<!--br>
						사진첨부 <input type="file" name="attachfile_1"><br-->
						<br>
						
						<textarea name='content' style='width:505px;height:325px;'><? echo $document_content;?></textarea><br>
						<br>
						내용 키워드<br>
						<input type="text" name="tags"
						
									value="<? 
									
									// 태그출력
									$sql="
										SELECT A.word, A.tag_idx 
										FROM ndd_list_tag A, ndd_document_tag B
										WHERE A.tag_idx = B.tag_idx
											AND B.document_idx = '$document_idx'
										;
									";
		
									$result = mysql_query($sql,$connect);
		
									$tag_count = 0;
		
									while($row = mysql_fetch_row($result))
									{
										if($tag_count !=0 )
											echo ", ";
									
										echo $row[0];
		
		
										$tag_count=1;
									
		
									}
									?>"
						
						
						
						
						style='width:505px;'><br> 콤마(,)로 구분하여 입력<br>
						<br>
		
					</div>
				
					<?
					
					/*
						if ($document_idx !="")
						{
							$sql="
								SELECT file_idx, original_name, size, download_count FROM ndd_file
								WHERE document_idx = $document_idx;
							";
	
							$result = mysql_query($sql,$connect);
	
							while($row = mysql_fetch_row($result))
							{
								echo "<a href='board_download.php?file_idx=".$row[0]."' target='_blank'>".$row[1]."(".number_format($row[2])."KB)</a> - ".$row[3]."회 다운로드됨<br><br>";
							}
						}
						
					*/	
					?>
					<!--br>
					파일첨부 1 : <input type="file" name="attachfile_1"><br>
					파일첨부 2 : <input type="file" name="attachfile_2"><br>
					파일첨부 3 : <input type="file" name="attachfile_3"><br>
					파일첨부 4 : <input type="file" name="attachfile_4"><br>
					파일첨부 5 : <input type="file" name="attachfile_5"><br>
					<br>
					<br-->
					<div style='width:100%;height:35px;padding-left:72px;float:left;'></div>

					
					<div style='width:714px;height:1px;margin-left:30px;float:left;background:#e6e6e6;'><span></span></div>
					<div style='width:714px;height:1px;margin-left:30px;float:left;background:#ffffff;'><span></span></div>
					<div style='width:100%;height:11px;float:left;'><span></span></div>

					<div style='width:100%;height:75px;padding-left:72px;float:left;'>
						<a style='cursor:pointer;' onclick='fwrite.submit();'><img src='./img/ndd_talk_save.png' border="0"></a>&nbsp;<a style='cursor:pointer;' onclick='history.back();'><img src='./img/ndd_talk_cancel.png' border="0"></a>
						
					</div>
				</form>
			
			
			</div>
			<? include "footer.php";?>		
		</div>

		
		<iframe src='' name='ifr_temp' style='display:none;'></iframe>



	</div>
 </body>
</html>
